﻿using System.Drawing;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using Overload.Phases;

namespace Overload.Testing.Phases
{
    [TestFixture]
    public class PlacementPhaseTests
    {
        private World world;
        private Unit unit;
        private PlacementPhase placementPhase;

        #region Test Setup

        [SetUp]
        public void SetUp()
        {
            world = new World(10, 10);
            placementPhase = new PlacementPhase(world);
            unit = new Unit(world);
        }

        #endregion

        #region Test: Units May Be Placed Along The Side of the Map

        [Test]
        public void TestUnitsMayBePlacedAlongTheSideOfTheMap()
        {
            // 4 tiles down on the left hand side
            placementPhase.PlaceUnit(unit, new Point(-4, -4));

            Assert.That(unit.WorldLocation, Is.EqualTo(new Point(-4, -4)));
        }

        #endregion
        #region Test: Units Can Only Be Placed On The Map (not outside it)

        [Test]
        [ExpectedException(typeof(InvalidLocationException))]
        public void TestUnitsCanOnlyBePlacedOnTheMap()
        {
            // Would be beyond topleft
            placementPhase.PlaceUnit(unit, new Point(5, 0));
        }

        #endregion
        #region Test: Units May Only Be Placed On The Edges of the Map

        [Test]
        [ExpectedException(typeof(InvalidLocationException))]
        public void TestUnitsMustBePlacedOnWorldSides()
        {
            // 5 towards world center, from top left
            placementPhase.PlaceUnit(unit, new Point(-5, 0));
        }

        #endregion
        #region Test: Units May Only Be Placed Once

        [Test]
        [ExpectedException(typeof(UnitAlreadyPlacedException))]
        public void TestUnitsCannotBePlacedMoreThanOnce()
        {
            placementPhase.PlaceUnit(unit, new Point(0, 0));
            placementPhase.PlaceUnit(unit, new Point(-5, 0));
        }

        #endregion
    }
}